package com.week.tiny_video.service.impl;

import com.week.tiny_video.dao.HistoryDao;
import com.week.tiny_video.pojo.History;
import com.week.tiny_video.pojo.User;
import com.week.tiny_video.service.HistoryService;
import com.week.tiny_video.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryDao historyDao;

    @Autowired
    private UserService userService;
    @Override
    public History get(int id) {
        return historyDao.findById(id).orElse(null);
    }

    @Override
    public void add(History history) {
        historyDao.save(history);
    }

    @Override
    public void update(History history) {
        historyDao.save(history);
    }

    @Override
    public void delete(int id) {
        historyDao.deleteById(id);
    }

    @Override
    public List<History> list(int uid) {
        User user = userService.getById(uid);
        return historyDao.findAllByUser(user);
    }
}
